package day0726API;

public class Test10 {
    public static void main(String[] args) {

        Thread woker=new Thread(){
            public void run() {
                try{
                    this.setName("工人：");
                    System.out.println(Thread.currentThread().getName()+"正在干活");
                    System.out.println(Thread.currentThread().getName()+"活干完了，开始休息");
                    Thread.sleep(1000000);
                    System.out.println(Thread.currentThread().getName()+"休息结束，继续干活");
                }catch (InterruptedException e){
                    System.err.println(e.getMessage()+"::"+Thread.currentThread().getName()+"的睡眠被打断了");
                }
            }
        };
        woker.start();


        Thread  master=new Thread(()->{//run方法参数保留，方法定义省略，方法体保留
            //run方法的代码：
            Thread.currentThread().setName("雇主：");
            System.out.println(Thread.currentThread().getName()+"正在检查工程质量");
            System.out.println(Thread.currentThread().getName()+"发现工程质量");
            woker.interrupt();//打断worker线程的sleep阻塞撞他(worker线程就会出现InterruptedException)
        });
        master.start();

    }
}
